<?php
	require_once('useraccesscontrol.class.php');
	require_once('databaseevent.class.php');
	require_once('configdatabase.class.php');
	
	$userAccessControl = new UserAccessControl();

	// For now, let us just assume that an event is pending if the user is not a mod.
	$pending = !$userAccessControl->isMod();
	$verb = $userAccessControl->isMod() ? 'eintragen' : 'vorschlagen';
	
	$message = null;
	if (isset($_POST['addeventsubmit'])) {
		if (0 < strlen($_POST['title'])) {
			$database = new ConfigDatabase();
			$event = new DatabaseEvent(null, new DateTime($_POST['datetime']), $_POST['title'], $_POST['description'], $pending);
			$event->write($database->getConnection());
			$message = $userAccessControl->isMod() ? 'Neues Event wurde eingetragen.' : 'Neues Event wurde vorgeschlagen und wird nach einer &Uuml;berpr&uuml;fung durch unsere Moderatoren freigeschaltet.';
		}
	}
?>
<html>
	<head>
		<title>Neues Event <?php echo($verb); ?></title>
		<link rel="stylesheet" type="text/css" href="style.css" />
	</head>
	<body>
		<h1>Neues Event <?php echo($verb); ?></h1>
		<?php if (null !== $message): ?>
			<p class="message"><?php echo($message); ?></p>
		<?php endif; ?>
		<form action="addevent.php" method="post">
			<table class="wide">
				<tr><td class="key"><label for="datetime">Datum/Uhrzeit:</label></td><td><input type="text" name="datetime" /></td></tr>
				<tr><td class="key"><label for="title">Titel:</label></td><td><input type="text" name="title" /></td></tr>
				<tr><td class="key"><label for="description">Beschreibung:</label></td><td><textarea name="description" style="width: 450px; height: 100px;"></textarea></tr>
			</table>
			<div class="wmd-preview"></div>
			<input type="submit" name="addeventsubmit" value="Eintragen" />
		</form>
		<div id="bottomlinks">
			<a href="modmenu.php">Modmen&uuml;</a>
			| <a href="index.php">Zur&uuml;ck zur Startseite</a>
			<br style="clear: both;" />
		</div>
		<script type="text/javascript">/*<![CDATA[*/wmd_options={output:"Markdown"};/*]]>*/</script>
		<script type="text/javascript" src="http://static.wmd-editor.com/v2/wmd.js"></script>
	</body>
</html>